import React from 'react';
export default function request(url,options = {}){
	if(options.method && options.method.toLowerCase() !== 'get'){
	    options.body = JSON.stringify(options.body || {});
	    options.headers = {
	        "Content-Type":"application/json",
	
	    }
	
	}
	options.headers = {
	    ...(options.headers || {}),
	    token:localStorage.token,
	}
	const baseUrl = 'http://jacklv.cn';
	fetch(baseUrl + url, options)
	  .then(response => {
	    return response.json();
	  })
	  .then(res => {
	    console.log('res', res)
	    if(res.code == 1){
	     return res.data;
	    }else{
			 message.error(res.msg || "出错了");
	      return Promise.reject(res);
	    }
	  })
}